home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / mpeg / video.h < prev   
C/C++ Source or Header  |  1994-08-01  |  11KB  |  289 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <stdio.h>
  22. #include <setjmp.h>
  23.  
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26.  
  27. #ifdef SH_MEM
  28. #include <sys/ipc.h>
  29. #include <sys/shm.h>
  30. #include <X11/extensions/XShm.h>
  31. #endif
  32.  
  33. /* X11/xmd.h correctly defines INT32, etc */
  34. #ifndef XMD_H
  35. typedef int INT32;
  36. typedef short INT16;
  37. typedef char INT8;
  38. #endif
  39. typedef unsigned int UINT32;
  40. typedef unsigned short UINT16;
  41. typedef unsigned char UINT8;
  42.  
  43. /* Define Parsing error codes. */
  44.  
  45. #define SKIP_PICTURE -10
  46. #define SKIP_TO_START_CODE -1
  47. #define PARSE_OK 1
  48.  
  49. /* Define BOOLEAN, TRUE, and FALSE. */
  50.  
  51. #define BOOLEAN int
  52. #define TRUE 1
  53. #define FALSE 0
  54.  
  55. /* Set ring buffer size. */
  56.  
  57. #define RING_BUF_SIZE 5
  58.  
  59. /* Macros for picture code type. */
  60.  
  61. #define I_TYPE 1
  62. #define P_TYPE 2
  63. #define B_TYPE 3
  64.  
  65. /* Start codes. */
  66.  
  67. #define SEQ_END_CODE 0x000001b7
  68. #define SEQ_START_CODE 0x000001b3
  69. #define GOP_START_CODE 0x000001b8
  70. #define PICTURE_START_CODE 0x00000100
  71. #define SLICE_MIN_START_CODE 0x00000101
  72. #define SLICE_MAX_START_CODE 0x000001af
  73. #define EXT_START_CODE 0x000001b5
  74. #define USER_START_CODE 0x000001b2
  75.  
  76. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  77.  
  78. #define MB_QUANTUM 100
  79.  
  80. /* Macros used with macroblock address decoding. */
  81.  
  82. #define MB_STUFFING 34
  83. #define MB_ESCAPE 35
  84.  
  85. /* Lock flags for pict images. */
  86.  
  87. #define DISPLAY_LOCK 0x01
  88. #define PAST_LOCK 0x02
  89. #define FUTURE_LOCK 0x04
  90.  
  91. #define HYBRID_DITHER 0
  92. #define HYBRID2_DITHER 1
  93. #define FS4_DITHER 2
  94. #define FS2_DITHER 3
  95. #define FS2FAST_DITHER 4
  96. #define Twox2_DITHER 5
  97. #define GRAY_DITHER 6
  98. #define FULL_COLOR_DITHER 7
  99. #define NO_DITHER 8
  100. #define ORDERED_DITHER 9
  101. #define MONO_DITHER 10
  102. #define MONO_THRESHOLD 11
  103. #define ORDERED2_DITHER 12
  104. #define MBORDERED_DITHER 13
  105.  
  106. /* External declaration of row,col to zig zag conversion matrix. */
  107.  
  108. extern int scan[][8];
  109.  
  110. /* Temporary definition of time stamp structure. */
  111.  
  112. typedef int TimeStamp;
  113.  
  114. /* Structure with reconstructed pixel values. */
  115.  
  116. typedef struct pict_image {
  117.   unsigned char *luminance;              /* Luminance plane.   */
  118.   unsigned char *Cr;                     /* Cr plane.          */
  119.   unsigned char *Cb;                     /* Cb plane.          */
  120.   unsigned char *display;                /* Display plane.     */
  121.   int locked;                            /* Lock flag.         */
  122.   TimeStamp show_time;                   /* Presentation time. */
  123.  
  124. #ifdef SH_MEM
  125.   XShmSegmentInfo shminfo;               /* Segment info.  */
  126.   XImage *ximage;                        /* Ximage struct. */
  127. #endif
  128.  
  129. } PictImage;
  130.  
  131. /* Group of pictures structure. */
  132.  
  133. typedef struct GoP {
  134.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  135.   unsigned int tc_hours;                 /* Hour component of time code.   */
  136.   unsigned int tc_minutes;               /* Minute component of time code. */
  137.   unsigned int tc_seconds;               /* Second component of time code. */
  138.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  139.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  140.                         previous group of pictures.    */
  141.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  142.   char *ext_data;                        /* Extension data.                */
  143.   char *user_data;                       /* User data.                     */
  144. } GoP;
  145.  
  146. /* Picture structure. */
  147.  
  148. typedef struct pict {
  149.   unsigned int temp_ref;                 /* Temporal reference.             */
  150.   unsigned int code_type;                /* Frame type: P, B, I             */
  151.   unsigned int vbv_delay;                /* Buffer delay.                   */
  152.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  153.                         pixel values flag.              */
  154.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  155.   unsigned int forw_f;                   /* Used for vector decoding.       */
  156.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  157.                         pixel values flag.              */
  158.   unsigned int back_r_size;              /* Used in decoding.               */
  159.   unsigned int back_f;                   /* Used in decoding.               */
  160.   char *extra_info;                      /* Extra bit picture info.         */
  161.   char *ext_data;                        /* Extension data.                 */
  162.   char *user_data;                       /* User data.                      */
  163. } Pict;
  164.  
  165. /* Slice structure. */
  166.  
  167. typedef struct slice {
  168.   unsigned int vert_pos;                 /* Vertical position of slice. */
  169.   unsigned int quant_scale;              /* Quantization scale.         */
  170.   char *extra_info;                      /* Extra bit slice info.       */
  171. } Slice;
  172.  
  173. /* Macroblock structure. */
  174.  
  175. typedef struct macroblock {
  176.   int mb_address;                        /* Macroblock address.              */
  177.   int past_mb_addr;                      /* Previous mblock address.         */
  178.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  179.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  180.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  181.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  182.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  183.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  184.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  185.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  186.   unsigned int cbp;                      /* Coded block pattern.             */
  187.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  188.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  189.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  190.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  191.   int recon_right_for_prev;              /* Past right forw. vector.         */
  192.   int recon_down_for_prev;               /* Past down forw. vector.          */
  193.   int recon_right_back_prev;             /* Past right back vector.          */
  194.   int recon_down_back_prev;              /* Past down back vector.           */
  195. } Macroblock;
  196.  
  197. /* Block structure. */
  198.  
  199. typedef struct block {
  200.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  201.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  202.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  203.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  204. } Block;
  205.  
  206. /* Video stream structure. */
  207.  
  208. typedef struct vid_stream {
  209.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  210.   unsigned int v_size;                         /* Vert. size in pixels.      */
  211.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  212.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  213.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  214.   unsigned char picture_rate;                  /* Code for picture rate.     */
  215.   unsigned int bit_rate;                       /* Bit rate.                  */
  216.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  217.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  218.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  219.                           intracoded frames.         */
  220.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  221.                           non intracoded frames.     */
  222.   char *ext_data;                              /* Extension data.            */
  223.   char *user_data;                             /* User data.                 */
  224.   GoP group;                                   /* Current group of pict.     */
  225.   Pict picture;                                /* Current picture.           */
  226.   Slice slice;                                 /* Current slice.             */
  227.   Macroblock mblock;                           /* Current macroblock.        */
  228.   Block block;                                 /* Current block.             */
  229.   int state;                                   /* State of decoding.         */
  230.   int bit_offset;                              /* Bit offset in stream.      */
  231.   unsigned int *buffer;                        /* Pointer to next byte in
  232.                           buffer.                    */
  233.   int buf_length;                              /* Length of remaining buffer.*/
  234.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  235.   int max_buf_length;                          /* Max lenght of buffer.      */
  236.   PictImage *past;                             /* Past predictive frame.     */
  237.   PictImage *future;                           /* Future predictive frame.   */
  238.   PictImage *current;                          /* Current frame.             */
  239.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  240. } VidStream;   
  241.  
  242. /* Declaration of global pointer to current video stream. */
  243.  
  244. extern VidStream *curVidStream;
  245.  
  246. /* Declarataion of global display pointer. */
  247. extern Display *display;
  248.  
  249. /* Shared memory flag. */
  250. extern int shmemFlag;
  251.  
  252. /* Quiet mode flag. */
  253. extern int quietFlag;
  254.  
  255. /* Dither flags external declaration. */
  256. extern char *ditherFlags;
  257.  
  258. /* Definition of Contant integer scale factor. */
  259.  
  260. #define CONST_BITS 13
  261.  
  262. /* Misc DCT definitions */
  263. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  264. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  265.  
  266. #define GLOBAL            /* a function referenced thru EXTERNs */
  267.   
  268. typedef short DCTELEM;
  269. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  270.  
  271.  
  272. #ifdef SH_MEM
  273. extern int gXErrorFlag;
  274. #endif
  275.  
  276. extern double realTimeStart;
  277. extern int totNumFrames;
  278. extern int loopFlag;
  279. extern int noDisplayFlag;
  280. extern jmp_buf env;
  281.  
  282. #ifdef ANALYSIS
  283. extern unsigned int bitCount;
  284. extern int showEachFlag;
  285. extern unsigned int cacheHit[8][8];
  286. extern unsigned int cacheMiss[8][8];
  287. #endif
  288.  
  289.